| Per lavorare con la personalizzazione delle stampe tramite scripting basta settare l'opzione nella ReportsX del layout di stampa del programma desiderato 'Scripting = 0/-1', utilizzata per attivare o meno il motore di script in fase di stampa. Ad esempio nel caso volessimo settare l'attivazione dello scripting per il programma della gestione documenti: 
  Nel registro configuriamo la proprietà script: 
  Il motore di script viene caricato nella ReportPeInit, quindi ogni volta che viene lanciata una stampa. Tale motore usa il file BE__CRPE.NTS che deve essere presente nella script del server (esattamente come per gli altri file di script). 
  Impostando ad esempio il seguente codice all'interno del file BE__CRPE: <nts>
<scriptCode><![CDATA[
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports NTSInformatica.CLN__STD
Imports NTSInformatica
Imports NTSInformatica.CLD__BASE
Imports System.IO
Public Class BE__CRPEVBS
  Implements INT__SCRIPT
  Dim oCldBase As CLD__BASE
  Dim arParam As New List(Of Object)
  Dim fErr As StreamWriter = Nothing
  Dim fiErr As FileInfo = Nothing
  Dim strNomeFileLog As String = ""
  Public Function Exec(ByVal strCommand As String, 
                       ByRef oApp As Object, 
                       ByRef oIn As Object, 
					   ByRef oParam As Object) As Object Implements INT__SCRIPT.Exec
    '------------------------------------
    'PARAMETRI PASSATI DAL CHIAMANTE
    'arParam(0) 
    'potrebbe valore nothing se la crpe è stata chiamata da un entity,
	'diversamente contiene la form che ha lanciato il report
    'arParam(1) 
    'nome del programma 'BS--PAGA' (occhio: bs--paga, non bn--paga!!!)
    'arParam(2)
    'Reports1, Reports2, ...
    'arParam(3)
    'Numero del Rep: 1, 2, 3, ... 10
    'arParam(4)
    'Tipo documento
    'arParam(5)
    'valore di default della proprietà (può essere un numero, 
	'una stringa o un valore boolean): non disponibile per 'ScriptPrint'
    '------------------------------------
    Try
      oCldBase = New CLD__BASE
      oCldBase.Init(oApp)
      arParam = oIn 'memorizzo i PARAMETRI PASSATI DAL CHIAMANTE 
      Try
        strNomeFileLog = oApp.ServerDir & "\Script\BE__CRPE.LOG"
        fiErr = New FileInfo(strNomeFileLog)
        If fiErr.Exists Then
          If fiErr.Length > 500000 Then fiErr.Delete()
        End If
        fErr = New StreamWriter(strNomeFileLog, True)
        fErr.Write(strCommand.ToUpper & vbCrLf)
        If Not arParam(0) Is Nothing Then
          fErr.Write("arParam(0) = " & CType(arParam(0), FRM__CHIL).Name & vbCrLf)
        Else
          fErr.Write("arParam(0) = Nothing" & vbCrLf)
        End If
        fErr.Write("arParam(1) = " & NTSCStr(arParam(1)) & vbCrLf)
        fErr.Write("arParam(2) = " & NTSCStr(arParam(2)) & vbCrLf)
        fErr.Write("arParam(3) = " & NTSCStr(arParam(3)) & vbCrLf)
        fErr.Write("arParam(4) = " & NTSCStr(arParam(4)) & vbCrLf)
        fErr.Write("arParam(5) = " & NTSCStr(arParam(5)) & vbCrLf)
        fErr.Flush()
        fErr.Close()
      Catch exlog As Exception
        Try
          fErr.Flush()
        Catch exlog1 As Exception
        End Try
        Try
          fErr.Close()
        Catch exlog1 As Exception
        End Try
      End Try
      Select Case strCommand.ToUpper()
        'Case "template" : Return template(oApp)
        'Case "BSVEBOLL_REPORTS1_REP1_REPORTNAMECOND"
		  'Return BSVEBOLL_REPORTS1_REP1_REPORTNAMECOND(oApp)
        'Case "BSVEBOLL_REPORTS1_REP1_PRINTERNAMECOND"
		  'Return BSVEBOLL_REPORTS1_REP1_PRINTERNAMECOND(oApp)
      End Select
      Return Nothing
    Catch ex As Exception
      CLN__STD.GestErr(ex, Me, "")
      Return Nothing
    End Try
  End Function
  'Function template(ByRef oApp As Object) As Object
  '  Try
  '    Return Nothing
  '  Catch ex As Exception
  '    CLN__STD.GestErr(ex, Me, "")
  '    Return Nothing
  '  End Try
  'End Function
  'Function BSVEBOLL_REPORTS1_REP1_REPORTNAMECOND(ByRef oApp As Object) As Object
  '  Try
  '    If Not arParam(0) Is Nothing Then
  '      If arParam(0).edSerieDoc.text = "R" Then
  '        Return "BSVEBOLL_B.RPT"
  '      Else
  '        Return "BSVEBOLL_A.RPT"
  '      End If
  '    Else
  '      Return arParam(5)
  '    End If
  '    Return Nothing
  '  Catch ex As Exception
  '    CLN__STD.GestErr(ex, Me, "")
  '    Return Nothing
  '  End Try
  'End Function
  'Function BSVEBOLL_REPORTS1_REP1_PRINTERNAMECOND(ByRef oApp As Object) As Object
  '  Try
  '    Return "OKI B410"
  '  Catch ex As Exception
  '    CLN__STD.GestErr(ex, Me, "")
  '    Return Nothing
  '  End Try
  'End Function
End Class
]]></scriptCode>
</nts>
 Noteremo che rilanciando la stampa del report della gestione documenti (fattura), se abbiamo impostato lo script precedente in BE__CRPE, verrà prodotto il seguente file di LOG: 
  Proviamo ad usare usare uno degli eventi indicati (BSVEBOLL_REPORTS1_REP1_REPORTNAMECOND) per impostare ad esempio un certo nome di report a seconda della serie, nel codice precedente aggiorneremo il case copiando l'evento voluto dal file di LOG, in realtà l'esempio è già predisposto è basta togliere il commento:       Select Case strCommand.ToUpper()
        'Case "template" : Return template(oApp)
        Case "BSVEBOLL_REPORTS1_REP1_REPORTNAMECOND"
		  Return BSVEBOLL_REPORTS1_REP1_REPORTNAMECOND(oApp)
        'Case "BSVEBOLL_REPORTS1_REP1_PRINTERNAMECOND"
		  'Return BSVEBOLL_REPORTS1_REP1_PRINTERNAMECOND(oApp)
      End Select
      Return Nothing
    Catch ex As Exception
      CLN__STD.GestErr(ex, Me, "")
      Return Nothing
    End Try
  End Function
  Function BSVEBOLL_REPORTS1_REP1_REPORTNAMECOND(ByRef oApp As Object) As Object
    Try
      If Not arParam(0) Is Nothing Then
        If arParam(0).edSerieDoc.text = "R" Then
          Return "BSVEBOLL_B.RPT"
        Else
          Return "BSVEBOLL_A.RPT"
        End If
      Else
        Return arParam(5)
      End If
      Return Nothing
    Catch ex As Exception
      CLN__STD.GestErr(ex, Me, "")
      Return Nothing
    End Try
  End Function
 Fatta questa modifica se rifacciamo la stampa verrà lanciato il report BSVEBOLL_A.RPT 
  Per ulteriori informazioni sulla realizzazione delle personalizzazioni tramite script consultare l'apposita circolare tecnica CT-0907-0027-Script e source extender.pdf. |